package com.brunobas.pontosmart;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.widget.ImageView;

public class TesteImgemView extends ImageView {

	Path ponteiro;
	Paint paint;
 
	boolean primeiraVez;
	 
	float angulo;
	
	public TesteImgemView(Context context, AttributeSet attrs)
	{
		super(context);
		
		paint = new Paint();
		ponteiro = new Path();
 
		paint.setColor(Color.RED);
		paint.setAntiAlias(true);
		
		primeiraVez = true;
		 
		angulo = 0;
	}
	
	
	@Override
	protected void onDraw(Canvas canvas)
	{
		canvas.save();
 
		super.onDraw(canvas);
 
		if(primeiraVez)
		{
			criaPath();
			primeiraVez = false;
		}
 
		canvas.rotate(angulo,this.getWidth()/2, this.getHeight()/2);
 
		canvas.drawCircle(this.getWidth()/2, this.getHeight()/2, this.getHeight()/20, paint);
		canvas.drawPath(ponteiro, paint);
 
		canvas.restore();
	}
 
	public void desenhar(float a)
	{
		angulo = a;
		invalidate();
	}
 
	public void criaPath()
	{
		ponteiro = new Path();
 
		ponteiro.moveTo((this.getWidth()/2)-8, this.getHeight()/2);
		ponteiro.lineTo((this.getWidth()/2)+8, this.getHeight()/2);
		ponteiro.lineTo((this.getWidth()/2)+8, (this.getHeight()/14)*12);
		ponteiro.lineTo((this.getWidth()/2)-8, (this.getHeight()/14)*12);
		ponteiro.close();
	}

}
